﻿using Abp.Application.Services;
using Abp.AspNetCore.Mvc.Authorization;
using Abp.Authorization;
using AbpZeroTemplate.Authorization;
using AbpZeroTemplate.Authorization.Accounts;
using AbpZeroTemplate.Authorization.Accounts.Dto;
using AbpZeroTemplate.Web.Controllers;
using AbpZeroTemplate.Web.Swagger;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace AbpZeroTemplate.Api.Admin.Controllers
{
    /// <summary>帐号相关
    /// </summary>
    [Area("Admin")]
    [Route("Admin/Account/[action]")]
    [ApiName("Admin")]
    [RemoteService]
    [AbpMvcAuthorize]
    public class AccountController : AbpZeroTemplateControllerBase
    {
        private readonly IAccountAppService _accountAppService;
        /// <summary>ctor
        /// </summary>
        public AccountController(IAccountAppService accountAppService)
        {
            _accountAppService = accountAppService;
        }

        /// <summary>判断某个租户是否可用
        /// </summary>
        [HttpPost]
        [AbpAllowAnonymous]
        public async Task<IsTenantAvailableOutput> IsTenantAvailable([FromBody]IsTenantAvailableInput input)
        {
            return await _accountAppService.IsTenantAvailable(input);
        }

        /// <summary>注册用户
        /// </summary>
        [HttpPost]
        public async Task<RegisterOutput> Register([FromBody]RegisterInput input)
        {
            return await _accountAppService.Register(input);
        }

        /// <summary>发送重置密码短信
        /// </summary>
        [HttpPost]
        public async Task SendPasswordResetCode([FromBody]SendPasswordResetCodeInput input)
        {
            await _accountAppService.SendPasswordResetCode(input);
        }

        /// <summary>重置密码
        /// </summary>
        [HttpPost]
        public async Task<ResetPasswordOutput> ResetPassword([FromBody]ResetPasswordInput input)
        {
            return await _accountAppService.ResetPassword(input);
        }

        /// <summary>发送邮箱激活链接
        /// </summary>
        [HttpPost]
        public async Task SendEmailActivationLink([FromBody]SendEmailActivationLinkInput input)
        {
            await _accountAppService.SendEmailActivationLink(input);
        }

        /// <summary>激活邮箱
        /// </summary>
        [HttpPost]
        public async Task ActivateEmail([FromBody]ActivateEmailInput input)
        {
            await _accountAppService.ActivateEmail(input);
        }

        /// <summary>
        /// </summary>
        [HttpPost]
        [AbpAuthorize(AppPermissions.Pages_Administration_Users_Impersonation)]
        public async Task<ImpersonateOutput> Impersonate([FromBody]ImpersonateInput input)
        {
            return await _accountAppService.Impersonate(input);
        }

        /// <summary>
        /// </summary>
        [HttpPost]
        public async Task<ImpersonateOutput> BackToImpersonator()
        {
            return await _accountAppService.BackToImpersonator();
        }

        /// <summary>
        /// </summary>
        [HttpPost]
        public async Task<SwitchToLinkedAccountOutput> SwitchToLinkedAccount([FromBody]SwitchToLinkedAccountInput input)
        {
            return await _accountAppService.SwitchToLinkedAccount(input);
        }
    }
}
